package com.road.yishi.dao;

import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

import com.road.entity.QuestCondiction;
import com.road.yishi.dao.impl.QuestCondictionDaoImpl;
import com.road.yishi.dao.utils.AppConfig;
import com.road.yishi.dao.utils.DefConfigFactory;
import com.road.yishi.db.BaseDao;
import com.road.yishi.db.pool.DBPoolMgr;

/**
 * @Description :
 * @FileName: Server.java
 * @Author :WeiHui.Zhang
 * @Data : 2016年2月23日 下午2:56:27
 * @Version:V1.00
 */
@Configuration
@ComponentScan
public class DaoFactory {

	private static ApplicationContext context;

	static {
		// 启动spring容器
		context = new AnnotationConfigApplicationContext(DaoFactory.class);
		// 生成开发环境的配置
		AppConfig devConfig = DefConfigFactory.createDEVConfig();
		DBPoolMgr.init(devConfig);
	}

	public static void main(String[] args) {
		QuestCondictionDao condictionDao = context.getBean(QuestCondictionDaoImpl.class);
		List<QuestCondiction> questCondictions = condictionDao.getQuestCondictions();
		for (QuestCondiction questCondiction : questCondictions) {
			System.out.println(questCondiction);
		}
	}

	public static <T extends BaseDao> T getDaoImpl(Class<T> clazz) {
		return context.getBean(clazz);
	}
}
